package com.ebupt.migu.music.common.util;

import com.google.common.io.Files;
import org.apache.commons.io.Charsets;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: TODO
 * @author: liuyangyang@ebupt.com
 * @date: 2021/4/27 14:43
 */
public class CompareFilesDiffFunc {

    public static void main(String[] args) throws IOException {
        String path = "D:\\bugs\\";
        String sourceFileName = "zhangyuan_20210506_canyuyonghu.csv";
        String aimFileName = "TB20210506172502-phone.csv";
        List<String> sources = Files.readLines(new File(path + sourceFileName), Charsets.UTF_8);
        List<String> aims = Files.readLines(new File(path + aimFileName), Charsets.UTF_8);
        int illegalNums = 0;
        File result = new File(path + "TB20210506172502.txt");
        for (String source : sources) {
            if (!aims.contains(source)) {
                if (!isMsisdn(source)) {
                    Files.append(source + "属于非法号段用户\n", result, Charsets.UTF_8);
//                    System.out.println(source + "属于非法号段用户");
                    illegalNums++;
                } else {
//                    System.out.println(source + "导入失败");
                    Files.append(source + "导入失败\n", result, Charsets.UTF_8);
                }
            }
        }
//        System.out.println("原始导入人群规模：" + sources.size());
//        System.out.println("最终导入人群规模：" + aims.size());
//        System.out.println("非法号段用户数：" + illegalNums);
        Files.append("原始导入人群规模：" + sources.size() + "\n", result, Charsets.UTF_8);
        Files.append("最终导入人群规模：" + aims.size() + "\n", result, Charsets.UTF_8);
        Files.append("非法号段用户数：" + illegalNums, result, Charsets.UTF_8);
    }

    private static boolean isMsisdn(String msisdn) {
        // Pattern pattern = Pattern.compile("^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$");
        Pattern pattern = Pattern.compile("^1[0-9]{10}$");
        Matcher matcher = pattern.matcher(msisdn);
        return matcher.matches();
    }
}
